package rov.util;


import java.io.*;


// misc. methods for convenience
public class Utils
{
    // converts celsius to fahrenheit
    public static double celsiusToFahrenheit(double tempC)
    {
     	return tempC * 9.0 / 5.0 + 32.0;
    }


    // Runs a system command.
    // Returns the output of the command when if finishes running.
    public static String run(String cmd)
    {
        String[] args = cmd.split(" ");
        StringBuffer buf = new StringBuffer();
        BufferedReader in = null;

        try
        {
            // start the external process
            Process p = Runtime.getRuntime().exec(args, null, null);

            // read its output
            in = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String input = null;

            while ((input = in.readLine()) != null)
                buf.append(input + "\n");

            boolean interrupted = true;

            // loop until the process has terminated
            while (interrupted)
            {
                try
                {
                    p.waitFor();
                    interrupted = false;
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                if (in != null)
                    in.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

        return buf.toString();
    }
}
